package com.example.book_system.mapper;

import com.example.book_system.model.BookInfo;
import com.example.book_system.model.PageRequest;
import com.example.book_system.model.PageResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {
    /**
     * 获取当前页信息
     * @param offset
     * @param limit
     * @return
     */
    @Select("select * from book_info where status != 0 " +
            "order by id asc " +
            "limit #{offset}, #{limit}")
    public List<BookInfo> queryBookInfoByPage(Integer offset, Integer limit);

    /**
     * 获取总记录数
     * @return
     */
    @Select("select count(1) from book_info where status != 0")
    public Integer queryCount();

    /**
     * 添加图书
     * @param bookInfo
     * @return
     */
    @Insert("insert into book_info (book_name, author, count, price, publish, status) " +
            "values(#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    public Integer addBook(BookInfo bookInfo);

    @Select("select * from book_info where id = #{BookId}")
    public BookInfo getBookById(Integer bookId);

    public void updateBook(BookInfo bookInfo);

    public void batchDeleteBook(List<Integer> ids);
}
